using System;
using NUnit.Framework;
using NHibernate.Persister.Entity;
using NHibernate.SqlCommand;
using NHibernate.Loader.Entity;
using NHibernate.Util;
using NHibernate.Loader.Collection;
using System.Collections.Generic;
using NHibernate.Loader;
using NHibernate.Engine;

namespace NHibernate.Test.Playground
{
    public class WorkingWithLoaders : SimpleDynamicProperties
    {
        readonly IDictionary<string, IFilter> _noFilters = new CollectionHelper.EmptyMapClass<string, IFilter>();
        [Test]
        public void can_get_unique_entity_loader()
        {
            var loader = BatchingEntityLoader.CreateBatchingEntityLoader(_persister, 100, LockMode.Read, sessions, _noFilters);
            Assert.IsNotNull(loader);
        }
        [Test]
        public void can_use_own_loader()
        {
            var loader = new MySampleLoader(sessions, _noFilters);
            using(var sess = OpenSession()) {
                Customer fred = new Customer(){ FirstName = "Fred"};
                fred.DynamicProperties["LastName"] = "Flintstone";
                Customer barney = new Customer(){ FirstName = "Barney"};
                barney.DynamicProperties["LastName"] = "Barney";
                sess.Save(fred);
                sess.Save(barney);
                var cmd = sess.Connection.CreateCommand();
                cmd.CommandText = "SELECT * FROM Customers";
                var reader = cmd.ExecuteReader();
                while(reader.Read()) {
                    

                }
            }
        }
        private AbstractEntityPersister _persister;
        protected override void OnSetUp()
        {
            base.OnSetUp();
            _persister = (AbstractEntityPersister)sessions.GetEntityPersister(typeof(Customer).FullName);
        }
    }

    public class MySampleLoader : OuterJoinLoader
    {
        public MySampleLoader(ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters)
            : base(factory, enabledFilters)
        {
        }

    }
}
